/*
 * @Descripttion: 
 * @version: 
 * @Author: by
 * @Date: 2021-12-10 16:25:06
 * @LastEditors: jgg
 * @LastEditTime: 2022-01-10 14:02:43
 */
import request from '../utils/request'

const tableMixin = {
	data() {
		return {
            mixinLoading: false,
            // 分页
			mixinPageOption: {
                page: 1,
                size: 10,
                total: 0,
            },
            // 表格基础配置
            mixinOption: {
                page: true,  // 开启分页
                index: true, // 开启索引
                indexTitle: '序号',
                selection: false,  // 多选
                addShow: true,  // 新增按钮
                border: true, // 开启边框,
                handleRowShow: true, //操作栏
                searchBtnShow: true, // 搜索按钮
                emptyBtnShow: true, // 表头清空按钮
                searchHeader: true, // 是否展示搜索表头
                stripe: true,  // 斑马纹
                rowKey: 'id', // 表格树标识符
                treeChildren: '', // 表格树子集字段
                hasChildren: '', // 表格树哪个字段开启子集
            }
		}
	},
    watch: {
    },
	methods: {
        handleCurrentChange(val) {
            this.mixinPageOption.page = val
            this.getData()
        },
		handleSizeChange(val) {
            this.mixinPageOption.page = 1
            this.mixinPageOption.size = val
            this.getData()
        },
        handelSearchForm(val) {
            this.getData(val)
        },
        clearSearchForm(val) {
            this.getData(val)
        },
        handelCommonDelete(row, url, method = 'get', type='id') {
            this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
                }).then(() => {
                    request({
                        url,
                        method,
                        params: {
                            [`${type}`]: row.id,
                        }
                    })
                        .then(res => {
                            this.$message.success(res.message || res.data.message || '删除成功')
                            this.getData()
                        })
                    
                }).catch(() => {})
            
                
        }
	}
}

export default tableMixin